package cn.zwx.common.xxl.job.starter;

import cn.zwx.base.exception.BizWrapException;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class SimpleJob {

    public static final Logger logger = LoggerFactory.getLogger(SimpleJob.class);


    /**
     *  测试定时任务
     * @param params params
     * @return com.xxl.job.core.biz.model.ReturnT<java.lang.String>
     * @author zhangwenxue
     **/
    @XxlJob(value = "simpleJob")
    public ReturnT<String> simpleJob(String params){
        long beginTime = System.currentTimeMillis();
        logger.info("===========测试定时任务定时任务,请求参数:{}==========，执行开始",params);
        ReturnT<String> returnT = null;
        try {
            // TODO 模拟处理业务
            String result = doProcess(params);
            logger.info("===========测试定时任务定时任务==========，结果：{}", result);
        } catch (BizWrapException e) {
            returnT = new ReturnT<>(ReturnT.FAIL_CODE, e.getMessage());
            logger.error("===========测试定时任务定时任务==========，业务执行异常", e);
        } catch (Exception e) {
            returnT = new ReturnT<>(ReturnT.FAIL_CODE, "任务执行异常");
            logger.error("===========测试定时任务定时任务==========，系统执行异常", e);
        } finally {
            logger.info("===========测试定时任务定时任务==========，执行结束，耗时：{}ms", System.currentTimeMillis() - beginTime);
        }
        return returnT;
    }

    private String doProcess(String params) throws BizWrapException{
        return "模拟处理业务";
    }

}
